var mgeUser = {
	tableid : "table1",
	layerindex : null,
	bsTable : null,
	idselect : null
};

mgeUser.clearInputs = function() {
	var ipts = $("#form_opt").find("input");
	ipts.each(function(i, v) {
		$(v).val("");
		var er = $(v).next();
		if (er != null) {
			er.remove();
		}
		var hs = $(v).parents(".col-md-8");
		hs.removeClass("has-success");
		hs.removeClass("has-error");
	});
}

mgeUser.queryParams = function() {
	return cmm.serializeObject($("#form_search"));
}
mgeUser.resHeigth = function() {
	var he = $(window).height() - ($("#divsearch").height() + 20);
	return he;
}
mgeUser.refresh = function(pageNumber) {
	mgeUser.bsTable.refresh(mgeUser.queryParams(), pageNumber);
}
mgeUser.load = function() {
	mgeUser.bsTable.load(mgeUser.queryParams());
}
var myLayout;
$(function() {
	myLayout = $('body').layout({
		north__minSize : 50,
		north__maxSize : 400,
		togglerContent_open : '<div class="ui-icon"></div>',
		togglerContent_closed : '<div class="ui-icon"></div>'
	// , spacing_open: 10
	// , spacing_closed: 10
	});
	var lay = layer.load({
		shade : [ 0.1 ]
	});
	$.ajax({
		url : ctx + "/mge/adx/rmrb/columns",
		data : {
			s_name : "rmrb"
		},
		dataType : 'json',
		type : 'post',
		success : function(d, st) {
			layer.close(lay);
			if (d.code == 200) {
				var colum = [];
				var fs = [];
				colum.push(fs);
				for ( var d3 in d.rows) {
					var d2 = d.rows[d3];
					var k = d2.columnName;
					fs.push({
						title : d2.columnName,
						field : d2.columnName,
						width : "200px",
						align : 'center',
						valign : 'middle'
					})
				}
				getData(colum);
			}
		},
		error : function(st) {
			layer.close(lay);
			layer.alert("请求失败，请重试或检查网络！");
		}
	})

	$("#form_search").on("submit", function(e) {
		mgeUser.bsTable.destroy()
		getData();
		return false;
	});
});

function getData(column) {
	var bs = new BgdataTable();
	var opt = new BgOption(mgeUser.tableid, ctx + "/mge/adx/rmrb/query?rad="
			+ new Date().getTime(), column, mgeUser.queryParams(), mgeUser
			.resHeigth());
	opt.toolbarId = "table1Toolbar";
	bs.draw(opt);
	mgeUser.bsTable = bs;
}